home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d17 / proff.arc / DOSTUFF2.C < prev    next >
Text File  |  1988-02-17  |  3KB  |  171 lines

  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include "proff.h"
  4. #include "debug.h"
  5.  
  6. struct hashlist *lookup(char *s, struct hashlist *hashtab[]);
  7.  
  8.  
  9. /*
  10.  * dodef - define a command macro (".de xx" is in buf.)
  11.  *
  12.  */
  13. dodef(buf,fd)
  14. char buf[];
  15. int fd;
  16. {
  17.     char name[MAXNAME],defn[MAXDEF];
  18.     int i;
  19.  
  20.     dprintf("dodef  ");
  21.     i = 0;
  22.     getwrd(buf, &i, name);
  23.     i = getwrd(buf, &i, name);    /* get the name */
  24.     if (i == 0)
  25.         error("missing name in command def.");
  26.     i = 0;
  27.     while (ngetln(buf,fd) != EOF) {
  28.         if (buf[0] == cchar && buf[1] == 'e' &&
  29.             buf[2] == 'n' && !isalnum(buf[3]))
  30.             break;
  31.         addstr(buf, defn, &i, MAXDEF);
  32.     }
  33.     if (addset(EOS, defn, &i, MAXDEF) == NO)
  34.         error("definition too long.\n");
  35.     if (install(name, defn, macrotab) == NULL)
  36.         fprintf(stderr,"no room for new definition.\n");
  37. #ifdef DEBUG
  38.     printf("dodef: %s (name) %s (defn)\n",name,defn);
  39. #endif
  40. }
  41.  
  42. /*
  43.  * doesc - expand escapes in buf
  44.  *
  45.  */
  46. doesc(buf, tbuf, size)
  47. char buf[];
  48. char tbuf[];
  49. int size;
  50. {
  51.     int i,j;
  52.  
  53.     dprintf("doesc  ");
  54.     j = 0;
  55.     for (i = 0; buf[i] != EOS && j < size-1; i++)
  56.         /*
  57.          * clean up generic escapes along the way.
  58.          */
  59.         if (buf[i] == genesc)
  60.             tbuf[j++] = buf[++i];
  61.  
  62.         else if (buf[i] != ESCAPE) {
  63.             tbuf[j] = buf[i];
  64.             j++;
  65.         }
  66.         else if (buf[i+1] == 'n' &&
  67.             (buf[i+2] >= 'a' && buf[i+2] <= 'z')) {
  68.             j += itoc(nr[buf[i+2] - 'a'],
  69.             &tbuf[j], size - j - 1);
  70.             i += 2;
  71.         }
  72.         else {
  73.             tbuf[j] = buf[i];
  74.             j++;
  75.         }
  76.     tbuf[j] = EOS;
  77.     strcpy(buf, tbuf);
  78. }
  79.  
  80. /*
  81.  * dovar - expand variables in buf
  82.  *
  83.  */
  84. dovar(tbuf, buf)
  85. char *buf;
  86. char *tbuf;
  87. {
  88.     register char *c, *p, t;
  89.     struct hashlist *xp;
  90.  
  91.     while (*buf != '\0') {
  92.         if (*buf == genesc) {
  93.             *tbuf++ = *buf++;
  94.             *tbuf++ = *buf;
  95.         }
  96.         else if (*buf != VESCAPE)
  97.             *tbuf++ = *buf;
  98.         else {
  99.             buf++;     /* skip the ESCAPE */
  100.             if (*buf == '{')
  101.                 buf++;
  102.             p = buf; /* save the beginning address of variable */
  103.             while (isalnum(*buf))
  104.                 buf++;
  105.             t = *buf;    /* save the character*/
  106.             *buf = '\0';    /* hack a null there */
  107.             if ((xp = lookup(p,gentab)) != NULL) {
  108.                 c = xp->def;    /* point to def */
  109.                 while (*c != '\0')
  110.                     *tbuf++ = *c++;
  111.             }
  112.             if (*(p-1) != '{')
  113.                 *tbuf++ = t;
  114.             else if (t != '}')
  115.                 fprintf(stderr, "missing \"}\" in %s\n",p);
  116.         }
  117.         buf++;
  118.     }
  119.     *tbuf = '\0';
  120. }
  121.  
  122.  
  123. /*
  124.  * dotabs - expand tabs in buf
  125.  *
  126.  */
  127. dotabs(buf,tbuf,size)
  128. char buf[];
  129. char tbuf[];
  130. int size;
  131. {
  132.     int i,j;
  133.     dprintf("dotabs  ");
  134.  
  135.     j = 0;
  136.     for (i = 0; buf[i] != EOS && j < size - 1; i++)
  137.         if (buf[i] == '\t')
  138.             while (j < size - 1) {
  139.                 tbuf[j] = ' ';
  140.                 j++;
  141.                 if (tabs[j] == YES || j > INSIZE)
  142.                     break;
  143.             }
  144.         else {
  145.             tbuf[j] = buf[i];
  146.             j++;
  147.         }
  148.     tbuf[j] = EOS;
  149.     strcpy(buf, tbuf);
  150. }
  151.  
  152. /*
  153.  * docline - produce a "contents" line.
  154.  *
  155.  */
  156. docline(str,width,cline,page)
  157. char *str;
  158. int width;
  159. char *cline;
  160. int page;
  161. {
  162.     int i;
  163.  
  164.     for (i = 0; i < width - 6 && cline[i] != '\0'; i++)
  165.         str[i] = cline[i];
  166.     while (i < width - 6)
  167.         str[i++] = '.';
  168.     sprintf(str+i,"%5d\n",page);
  169. }
  170.  
  171.